const modules = import.meta.glob('/src/views/**/**.vue')
// 常量路由
const constrouters = [
	{
		path: '/login',
		name: 'login',
		component: () => import('@/views/common/login/index.vue')
	},
	{
		path: '/forget',
		name: 'forger',
		component: () => import('@/views/common/login/forgetpassword.vue')
	},
	{
		path: '/register',
		name: 'register',
		component: () => import('@/views/common/login/register.vue')
	},
	{
		path: '/dataline',
		name: 'dataline',
		component: () => import('@/views/common/dataline/index.vue')
	},
	{
		path: '/front',
		name: 'front',
		component: () => import('@/views/front/front.vue'),
		redirect: { name: 'frontindex' },
		children: [
			{
				path: '/front/index',
				name: 'frontindex',
				component: () => import('@/views/front/index/index.vue')
			},
			{
				path: '/front/video',
				name: 'frontvideo',
				component: () => import('@/views/front/video/index.vue')
			},
			{
				path: '/front/category',
				name: 'frontcategory',
				component: () => import('@/views/front/category/index.vue')
			},
			{
				path: '/front/category/comment',
				name: 'frontcategorycomment',
				component: () => import('@/views/front/category/comment.vue')
			},
			{
				path: '/front/information',
				name: 'frontinformation',
				component: () => import('@/views/front/information/index.vue')
			},
			{
				path: '/front/collect/video',
				name: 'frontcollectvideo',
				component: () => import('@/views/front/collect/videoIndex.vue')
			},
			{
				path: '/front/video/list',
				name: 'frontvideolist',
				component: () => import('@/views/front/video/list.vue')
			},
			{
				path: '/front/video/detail',
				name: 'frontvideodetail',
				component: () => import('@/views/front/video/detail.vue')
			},
			{
				path: '/front/detail',
				name: 'frontdetai111l',
				component: () => import('@/views/front/index/detail.vue')
			},
			{
				path: '/front/teach',
				name: 'frontteach',
				component: () => import('@/views/front/teach/index.vue')
			},
			{
				path: '/front/teach/detail',
				name: 'frontteachdetail',
				component: () => import('@/views/front/teach/detail.vue')
			},
			{
				path: '/front/map/comment',
				name: 'frontcomment',
				component: () => import('@/views/front/map/comment.vue')
			},
			{
				path: '/front/map',
				name: 'frontmap',
				component: () => import('@/views/front/map/index.vue')
			},
			{
				path: '/front/collect',
				name: 'frontcollect',
				component: () => import('@/views/front/collect/index.vue')
			},
			{
				path: '/front/equip',
				name: 'frontequip',
				component: () => import('@/views/front/equip/index.vue')
			},
			{
				path: '/front/equip/equipment/show',
				name: 'frontequipshow',
				component: () => import('@/views/front/equip/equipmentShow.vue')
			},
			{
				path: '/front/equip/equipment/suit/show',
				name: 'frontsuitshow',
				component: () => import('@/views/front/equip/suitShow.vue')
			},
			{
				path: '/front/equip/detail',
				name: 'frontdetail',
				component: () => import('@/views/front/equip/detail.vue')
			},
			{
				path: '/front/equip/suit',
				name: 'frontsuit',
				component: () => import('@/views/front/equip/suit.vue')
			},
			{
				path: '/front/npc',
				name: 'frontnpc',
				component: () => import('@/views/front/npc/index.vue')
			},
			{
				path: '/front/npc/detail',
				name: 'frontnpcdetail',
				component: () => import('@/views/front/npc/detail.vue')
			}
		]
	},
	{
		//404
		path: '/404',
		component: () => import('@/views/common/404/index.vue'),
		name: '404'
	}
]

// 获取菜单信息
const getRouters = data => {
	const res = data
	const router = [
		{
			path: '/',
			name: '',
			component: () => import('@/layout/index.vue'),
			redirect: '/home',
			children: [
				{
					path: '/home',
					name: 'home',
					component: import('@/views/system/home/index.vue'),
					meta: {
						icon: 'HomeFilled',
						title: '系统首页',
						hidden: false
					}
				},
				{
					path: '/information',
					name: 'information',
					component: import('@/views/common/information/index.vue'),
					meta: {
						icon: 'User',
						title: '个人信息',
						hidden: true
					}
				}
			]
		}
	]

	res.forEach(routeData => {
		router[0].children.push(addRouter(routeData))
	})
	router[1] = {
		//登录成功展示数据的路由
		path: '/:pathMatch(.*)*',
		redirect: '/404',
		name: 'Any',
		meta: {
			title: '404',
			hidden: true,
			icon: 'CircleCloseFilled'
		}
	}

	return router
}
// 菜单转成路由
const addRouter = routeData => {
	const route = {
		path: routeData.path,
		name: routeData.perms,
		meta: routeData.meta
	}
	route.component = modules[`/src/views${routeData.component}.vue`]
	if (routeData.children && routeData.children.length > 0) {
		route.redirect = routeData.children[0].path
		route.children = routeData.children.map(childRoute => addRouter(childRoute))
	}
	return route
}

export default constrouters
export { getRouters }
